/**window.onload=function(){
	changeRegisterTab();
}

function changeRegisterTab(){
	var regContent1=document.getElementById("content1");
	var regContent2=document.getElementById("content2");
	
	var regsubmit1=document.getElementById("step1Submit");
	var regsubmit2=document.getElementById("step2Submit");
		
	regsubmit1.onclick=function(){
		regContent2.style.display="block";
		regContent1.style.display="none";
	}
}*/



//条形码
//CharMode函数
//测试某个字符是属于哪一类
function CharMode(iN) {
	if (iN>=48 && iN <=57) //数字
	return 1;
	if (iN>=65 && iN <=90) //大写字母
	return 2;
	if (iN>=97 && iN <=122) //小写
	return 4;
	else
	return 8; //特殊字符
}

//bitTotal函数
//计算出当前密码当中一共有多少种模式
function bitTotal(num) {
	modes=0;
	for (i=0;i<4;i++) {
		if (num & 1) 
		modes++;
		num>>>=1;
	}
	return modes;
}

//checkStrong函数
//返回密码的强度级别
function checkStrong(sPW) {
	if (sPW.length<=4)
	return 0; //密码太短
	Modes=0;
	for (i=0;i<sPW.length;i++) {
		 //测试每一个字符的类别并统计一共有多少种模式
		 Modes|=CharMode(sPW.charCodeAt(i));
	}
	return bitTotal(Modes);
}

//pwStrength函数
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色
function pwStrength(pwd) {
	O_color="#eeeeee";
	L_color="#FF0000";
	M_color="#FF9900";
	H_color="#33CC00";
	if (pwd==null||pwd==''){
	Lcolor=Mcolor=Hcolor=O_color;
	}else {
		S_level=checkStrong(pwd);
		switch(S_level) {
		case 0:
			Lcolor=Mcolor=Hcolor=O_color;
		case 1:
			Lcolor=L_color;
			Mcolor=Hcolor=O_color;
			break;
		case 2:
			Lcolor=Mcolor=M_color;
			Hcolor=O_color;
			break;
		default:
			Lcolor=Mcolor=Hcolor=H_color;
		}
	}
	document.getElementById("strength_L").style.background=Lcolor;
	document.getElementById("strength_M").style.background=Mcolor;
	document.getElementById("strength_H").style.background=Hcolor;
	return;
}

$(function(){
	//邮箱校验
	$("#emailTip").text("请输入邮箱名").css("display","none");
	
	$("#emailNum").keyup(function(){
		
		$("#emailTip").text("请输入邮箱名").css("display","inline-block");
		var email=$.trim($(this).val());		
			var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var match=reg.test(email);
			if(match==false){
				if(email=="" ){
					$("#emailTip").css("background-position","-154px -435px");
					$("#emailTip").text("请输入邮箱名");
				}else{
					$("#emailTip").css("background-position","-154px -435px");
					$("#emailTip").text("输入的邮箱格式有误");
				}								
			}else{
				$("#emailTip").text(" ");
				$.post("registerServlet?t="+new Date(),{op:'checkEmail',email:email},function(data){
					data=parseInt( $.trim(data) );
					if(data==0){
						$("#emailTip").css("background-position","-154px -435px");
						$("#emailTip").text("该邮箱已被注册，请更换邮箱...");
					}else if(data==1){
						$("#emailTip").css("background-position","-1127px -410px");
						$("#emailTip").css("background-color","white");
						$("#emailTip").css("border","none");
						
					}else{
						$("#emailTip").css("background-position","-154px -435px");
						$("#emailTip").text("由于网络原因，请稍后重试...");
					}
				});
			}
		
	});
	
	//密码框校验
	$("#pwdOnceTip").text("6-18位，字母、数字、特殊符号中的两种或两种以上，不能单独使用某一种").css("display","none");
	
	$("#pwdOnce").keyup(function(){
		$("#pwdOnceTip").text("6-18位，字母、数字、特殊符号中的两种或两种以上，不能单独使用某一种").css("display","inline-block");
		var pwd=$(this).val();		
			var reg = /^(?![\d]+$)(?![a-zA-Z]+$)(?![!#$%^&*]+$)[\da-zA-Z!#$%^&*]{6,18}$/ ;
			var match=reg.test(pwd);
			if(match==false){
				if(pwd=="" ){
					$("#pwdOnceTip").css("background-position","-154px -435px");
					$("#pwdOnceTip").text("请输入密码");
				}else{
					$("#pwdOnceTip").css("background-position","-154px -435px");
					$("#pwdOnceTip").text("6-18位，字母、数字、特殊符号中的两种或两种以上，不能单独使用某一种");
				}								
			}else{
				$("#pwdOnceTip").text(" ");
				$("#pwdOnceTip").css("background-position","-1127px -410px");
				$("#pwdOnceTip").css("background-color","white");
				$("#pwdOnceTip").css("border","none");				
			}		
	});
	//确认密码校验
	$("#pwdTwiceTip").text("请输入确认密码").css("display","none");
	var pwdOnce;
	var pwdTwice;
	$("#pwdTwice").keyup(function(){
		pwdOnce=$("#pwdOnce").val();
		pwdTwice=$("#pwdTwice").val();
		$("#pwdTwiceTip").text("请输入确认密码").css("display","inline-block");	
		if(pwdOnce==""){
			$("#pwdTwiceTip").text("请输入密码").css("display","inline-block");
			$("#pwdTwiceTip").css("background-position","-154px -435px");
			
		}else{
			if(pwdOnce==pwdTwice){
				$("#pwdTwiceTip").text(" ");
				$("#pwdTwiceTip").css("background-position","-1127px -410px");
				$("#pwdTwiceTip").css("background-color","white");
				$("#pwdTwiceTip").css("border","none");				
			}else{
				$("#pwdTwiceTip").text("请输入确认密码").css("display","inline-block");		
			}
		}
	});
	
	
	//图形校验
	$("#verifCodeTip").text("请输入验证码").css("display","none");
	$("#verifCodeNumTip").text("请输入验证码").css("display","none");
	
});

//图形验证码
function changeCode(){
	$("#verifCodeImg").attr("src","valiCodeImg.jsp?t="+new Date());
}
var time=60;
var mytime;

function registerUserInfo(){
	var email=$("#emailNum").val();
	var pwdOnce=$("#pwdOnce").val();
	var pwdTwice=$("#pwdTwice").val();
	var verifCode=$("#verifCode").val();
	
	if(document.getElementById("argee").checked){
		$.post("registerServlet?t="+new Date(),{op:'step1Submit',email:email,pwdOnce:pwdOnce,pwdTwice:pwdTwice,verifCode:verifCode},function(data){
			data=parseInt($.trim(data));
			if(data==1){
				$("#verifCodeTip").text("请输入验证码").css("display","inline-block");
			}else if(data==2){
				$("#pwdTwiceTip").text("请输入确认密码").css("display","inline-block");
			}else if(data==3){
				$("#content1").css("display","none");
				$("#content2").css("display","block");	
				$("#extendemail").text(email);
				$("#regsafecodebtn").click(function(){
					$.post("registerServlet?t="+new Date(),{op:'sendCode',email:email},function(data){
						data=parseInt($.trim(data));
						if(data==1){
							$("#verifCodeNumTip").text("验证码已发送，请登录邮箱获取，完成注册...").css({"display":"inline-block","background-position":"-154px -435px"});
							$("#regsafecodebtn").attr("disable",true).val("重新发送(60s)");
							 mytime=setInterval("changeVal()", 1000);
							 $("#step2Submit").click(function(){
								 var regsafecode=$("#regsafecode").val();
								 $.post("registerServlet?t="+new Date(),{op:'step2Submit',email:email,pwdOnce:pwdOnce,pwdTwice:pwdTwice,verifCode:verifCode,regsafecode:regsafecode},function(data){
									data=parseInt($.trim(data));		
									if(data==1){
										location.href="registerok.html";
									}else{
										$("#verifCodeNumTip").text("验证码填写错误，请重新发送").css({"display":"inline-block","background-position":"-154px -435px"});
										mytime=setInterval("changeVal()", 1000);
									}
								 });
							 });
						}else{
							$("#verifCodeNumTip").css("background-position","-154px -435px");
							$("#verifCodeNumTip").text("由于网络原因，请稍后重试...");
						}
						
					});
				});
			}else{
				alert("注册失败...");
				$("#emailNum").text("");
				$("#pwdOnce").text("");
				$("#pwdTwice").text("");
			}
		});
	}else{
		alert("您必须同意协议才能注册...");
	}
}

function changeVal(){
	time--;
	$("#regsafecodebtn").val("重新发送("+time+"s)");
	if(time<=0){
		$("#regsafecodebtn").attr("disable",false).val("发送验证码");
		clearInterval(mytime);
	}
}

function registersubmit(){
	var regsafecode=$("#regsafecode").val();
	$.post("registerServlet?t="+new Date(),{op:'step2Submit',regsafecode:regsafecode},function(data){
		data=parseInt($.trim(data));
		if(data==1){
			location.href="registerok.html";
		}else{
			$("#verifCodeNumTip").text("验证码填写错误，请重新发送").css({"display":"inline-block","background-position":"-154px -435px"});
			mytime=setInterval("changeVal()", 1000);
		}
	});
}


